<?php
require 'Home/Model/IndexModel.php';
require 'Controller.php';
class IndexController extends Controller{
	function __construct(){
		parent::__construct();
             
	}
	function index(){
		$model=new IndexModel();
		$data=$model->getIndex();
        $this->assign("cartoons",$data);
        $this->display();
	}
	function listall(){
		$tid=$_GET['tid'];
		$model=new IndexModel();
		$data=$model->getlistall($tid);
        $this->assign("cartoon_c",$data);
        $this->display();

	}
	function show(){
		$cid=$_GET['cid'];
		$model=new IndexModel();
		$data=$model->getshow($cid);
		$this->assign("cartoon_s",$data);
		$this->display();
	}
          function comment(){
               session_start();
          $uname=$_SESSION["user"];
          $model = new IndexModel();
          $data = $model->comment($uname);
             // var_dump($data);
          $this->assign('user',$data);
          $uname=$_GET['uname'];
          if($data)
          {
            
          echo "留言成功，3秒后跳转。";
      header("refresh:3;url='index.php?c=index&m=index'");
          
            }
          }
          function commentlist(){
              session_start();

              echo $_SESSION['uid'];
           $model=new IndexModel();
           $data=$model->getcommentlist($uid);
           $this->assign("comment",$data);
              var_dump($data);
            $this->display();
          }
          function adminlist(){
            $this->display();
          }
          function adminlogin(){
            $data=$_POST;
            $model=new IndexModel();
            $result=$model->adminlist($data);
          if($result)
          {
           session_start();
           $_SESSION["admin"]=$data['adminname'];
          echo "登录成功，3秒后跳转。";
      header("refresh:3;url='admin.php?c=admin&m=adminlogin'");
           }else
          {
          echo "<h2>登录失败，3秒后返回登录</h2>";
           header("refresh:3;url='index.php?c=index&m=index'");
          }

          }
          

	function login(){
        $this->display();
	}
	function loginresult(){
		$data=$_POST;
		$model=new IndexModel();
		$result=$model->dologin($data);
		 if($result)
          {
           session_start();
           $_SESSION["user"]=$data['uname'];
              setcookie("user",$data['uname'],time()+3600*24);

              echo "登录成功，3秒后跳转。";
			header("refresh:3;url='index.php?c=index&m=index'");
           }else
          {
	        echo "<h2>登录失败，3秒后返回登录</h2>";
           header("refresh:3;url='index.php?c=index&m=login'");
          }
	}
	function reguser(){
		$this->display();
	}
          function adduser(){
          $data=$_POST;

          $model=new IndexModel();
          $result=$model->addUser($data);
          if($result)
          {
            echo '注册成功，3秒返回登录';
             header("refresh:3;url='index.php?c=index&m=login'");
          }
          else
            {
            echo '注册失败，3S返回继续注册' ;
             header("refresh:3;url='index.php?c=index&m=reguser'"); 
            }
          }
        function esclogin(){
        	session_start();
           $_SESSION["user"]=NULL;
            echo "注销成功，3秒后跳转。";
			header("refresh:3;url='index.php?c=index&m=index'");
        }
      function showuser(){
        	session_start();
           $uname=$_SESSION["user"];
           $model=new IndexModel();
           $data=$model->getshowuser($uname);
           $this->assign("user",$data);
		   $this->display();
        }
        function search(){
         @$cartoonname=$_GET['cartoonname'];
         $model = new IndexModel();
         $data = $model->search($cartoonname);
         $this->assign('cartoon',$data);
         $this->display(); 
        }
       function edituser(){
          $uid=$_GET['uid'];
            $model=new IndexModel();
            $data=$model->edituser($uid);
            $this->assign("users",$data);
            $this->display();
        }
        function updateuser(){
          $data=$_POST;
          $file=$_FILES;
          $model=new IndexModel();
          $result=$model->updateuser($data,$file);
           if($result)
          {
            echo '修改成功，3秒返回';
             header("refresh:3;url='index.php?c=index&m=index'");
          }
          else
            {
            echo '修改失败，3秒返回' ;
             header("refresh:3;url='index.php?c=index&m=index'"); 
            }
        }

}?>